package com.example.view_impl.popup_window;

import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.example.view_impl.R;
import com.zy.zlog.ZLog;


//研究文档：https://wkijriqbpn.feishu.cn/wiki/V2wUwwSwfiopYckA9ywcgvHxnmW
public class PopupWindowTestActivity extends AppCompatActivity {

    View base;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_window_test);
        base = findViewById(R.id.activity_popup_window_test_base);
        base.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopupWindow();
            }
        });

    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
        //showPopupWindow();
    }

    private void showPopupWindow() {
        //设置contentView
        View contentView = LayoutInflater.from(getBaseContext()).inflate(R.layout.popup_layout, null);
        PopupWindow mPopWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        mPopWindow.setContentView(contentView);
//        //设置各个控件的点击响应
//        TextView tv1 = (TextView)contentView.findViewById(R.id.pop_computer);
//        TextView tv2 = (TextView)contentView.findViewById(R.id.pop_financial);
//        TextView tv3 = (TextView)contentView.findViewById(R.id.pop_manage);
//        tv1.setOnClickListener(this);
//        tv2.setOnClickListener(this);
//        tv3.setOnClickListener(this);
        //显示PopupWindow
        IBinder ss = base.getWindowToken();
        ZLog.d("PopupWindowTestActivity", ss);
        mPopWindow.showAtLocation(base, Gravity.BOTTOM, 0, 0);

    }
}